
const cateModel = require('../model/cateModel');
// 获取所有分类
exports.getAllCate = (req,res)=>{
   
   cateModel.getAllCate((err,data)=>{
      // console.log(data)
      if(err){
         res.json({code:400,msg:'can not find anything'})
      }else{
         res.json({code:200,msg:'successful',data})
      }
   })
}

// 通过id修改分类
exports.editCateById = (req,res)=>{
   // 接收参数
   let obj = req.body
   //调用数据模块
   cateModel.editCateById(obj,(err)=>{
      if(err){
         res.json({code:400,msg:'failed to edit category'})
      }else{
         res.json({code:200,msg:'succeed to edit category'})
      }
   })
}

// 添加分类信息的方法
exports.addCateInfo = (req,res)=>{
   // 接收参数
   let obj = req.body
   console.log(obj)
   obj.id = null
   // 调动数据模块
   cateModel.addCateInfo(obj,(err)=>{
      if(err){
         // console.log(err)
         res.json({code:400,msg:'failed to add cate info'})
      }else{
         res.json({code:200,msg:'succeed to add cate info'})
      }
   })
}

//删除分类信息的方法
exports.deleteCateById = (req,res)=>{
   // 接收参数
   let id = req.query.id
   // console.log(id)
   // 调用数据模块
   cateModel.deleteCateById(id,(err)=>{
      if(err){
         console.log(err)
         res.json({code:400,msg:'failed to delete'})
      }else{
         res.json({code:200,msg:'succeed to delete'})
      }
   })
}